package com.leyou.service.impl;

import com.leyou.vo.SpecParamVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;



import com.leyou.dao.SpecParamDao;
import com.leyou.entity.SpecParamEntity;
import com.leyou.service.SpecParamService;


@Service("specParamService")
public class SpecParamServiceImpl extends ServiceImpl<SpecParamDao, SpecParamEntity> implements SpecParamService {

    @Override
    public List<SpecParamEntity> listByCid(Long cid) {
        return this.list(new QueryWrapper<SpecParamEntity>().eq("cid",cid));
    }

    @Override
    public void saveSpec(SpecParamVo specParam) {
        SpecParamEntity spa = new SpecParamEntity();
        BeanUtils.copyProperties(specParam,spa);
        if(specParam.getNumeric() != null){
          spa.setNumeric( specParam.getNumeric()==1L?1l:0l );
        }
        if(specParam.getSearching() != null){
          spa.setSearching( specParam.getSearching()== 1l?1l:0l );
        }
        if(specParam.getGeneric() != null){
          spa.setGeneric( specParam.getGeneric() == 1L?1l:0l );
        }
        this.saveOrUpdate(spa);
    }

    @Override
    public List<SpecParamEntity> listByGid(Long gid) {
        return this.list(new QueryWrapper<SpecParamEntity>().eq("group_id",gid));
    }
}